package logic

import (
	"context"
	"src/models/es"
	"src/models/mysql"

	"src/internal/svc"
	"src/src"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsToEsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsToEsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsToEsLogic {
	return &GoodsToEsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsToEsLogic) GoodsToEs(in *src.GoodsToEsRequest) (*src.GoodsToEsResponse, error) {
	// todo: add your logic here and delete this line

	var good []mysql.Good
	mysql.DB.Debug().Find(&good)
	es.SyncGoods(good)

	return &src.GoodsToEsResponse{}, nil
}
